from flask import Flask, jsonify, render_template,request
from util.Utils import DateEncoder
from news_api import NewsApi as na


# ================================ 对外提供接口 （头） ================================

app = Flask(__name__)
app.json_encoder = DateEncoder

@app.route('/getNewsData',methods=['GET'])
def getNewsData():
    page = request.args.get("page", 1, type=int)
    print(page)
    return jsonify(na.doSearch(page))


@app.route('/bignews')
def showHtml():
    return render_template('FinanceShow.html')

@app.route('/subway')
def subwayHtml():
    return render_template('subway.html')

@app.route('/log')
def logHtml():
    return render_template('log.html')

# ================================ 对外提供接口 （尾） ================================

# ==主程序==
def main():
    print("====开始执行Flask任务====")
    app.config["ENV"] = "development"
    app.config["DEBUG"] = True
    app.run(host='0.0.0.0', port=5000)
    # app.run(host='127.0.0.1', port=5000)




if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print('谢谢使用')
        exit(0)